package com.gisocn.onemap.ui.popupwindow;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.esri.core.geometry.Geometry;
import com.gisocn.onemap.base.Constant;
import com.gisocn.onemap.event.MessageEvent;
import com.gisocn.onemap.model.Collection;
import com.gisocn.onemap.model.LandInfo;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.ui.adapter.QueryLandInfoAdapter;
import com.gisocn.onemap.utils.SpUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.eventbus.EventBus;

/* loaded from: classes2.dex */
public class DetailLandInfoPopWindow extends PopupWindow {
    private QueryLandInfoAdapter adapter;
    private ArrayList<Collection> collectionList = new ArrayList<>();
    private Context context;
    private String dbName;
    private String displayField;
    private Geometry geometry;
    private int height;
    boolean isCollection;
    ImageView ivCollection;
    private String layerName;
    private ArrayList<LandInfo> list;
    private int pkId;
    private int width;

    public DetailLandInfoPopWindow(Context context, ArrayList<LandInfo> arrayList, Geometry geometry, int i, int i2, String str, String str2, String str3, int i3) {
        this.context = context;
        this.list = arrayList;
        this.width = i;
        this.height = i2;
        this.geometry = geometry;
        this.layerName = str;
        this.displayField = str2;
        this.dbName = str3;
        this.pkId = i3;
        initView();
    }

    private void initView() {
        this.isCollection = false;
        View inflate = View.inflate(this.context, R.layout.popup_query_land_info, null);
        setContentView(inflate);
        setWidth(this.width);
        setHeight(this.height);
        setFocusable(false);
        setOutsideTouchable(false);
        setBackgroundDrawable(new BitmapDrawable());
        this.ivCollection = (ImageView) inflate.findViewById(R.id.iv_menu);
        TextView textView = (TextView) inflate.findViewById(R.id.tv_close);
        RecyclerView recyclerView = (RecyclerView) inflate.findViewById(R.id.recycle_land_info);
        if (this.adapter == null) {
            recyclerView.setLayoutManager(new LinearLayoutManager(this.context));
            QueryLandInfoAdapter queryLandInfoAdapter = new QueryLandInfoAdapter(R.layout.item_query_land_info, this.list);
            this.adapter = queryLandInfoAdapter;
            recyclerView.setAdapter(queryLandInfoAdapter);
        }
        this.ivCollection.setVisibility(0);
        Glide.with(this.context).load(Integer.valueOf((int) R.mipmap.icon_uncollect)).into(this.ivCollection);
        textView.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.popupwindow.DetailLandInfoPopWindow.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                DetailLandInfoPopWindow.this.dismiss();
            }
        });
        this.ivCollection.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.popupwindow.DetailLandInfoPopWindow.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                Gson gson = new Gson();
                ArrayList arrayList = (ArrayList) gson.fromJson(SpUtils.get(DetailLandInfoPopWindow.this.context, "collection", "") + "", new TypeToken<List<Collection>>() { // from class: com.gisocn.onemap.ui.popupwindow.DetailLandInfoPopWindow.2.1
                }.getType());
                if (arrayList != null) {
                    DetailLandInfoPopWindow.this.collectionList.clear();
                    DetailLandInfoPopWindow.this.collectionList.addAll(arrayList);
                }
                Collection collection = new Collection();
                collection.setDisplayField(DetailLandInfoPopWindow.this.displayField);
                collection.setLayerName(DetailLandInfoPopWindow.this.layerName);
                collection.setDbName(DetailLandInfoPopWindow.this.dbName);
                collection.setId(DetailLandInfoPopWindow.this.pkId);
                collection.setLandInfos(DetailLandInfoPopWindow.this.list);
                if (DetailLandInfoPopWindow.this.isCollection) {
                    Glide.with(DetailLandInfoPopWindow.this.context).load(Integer.valueOf((int) R.mipmap.icon_uncollect)).into(DetailLandInfoPopWindow.this.ivCollection);
                    if (DetailLandInfoPopWindow.this.collectionList.contains(collection)) {
                        DetailLandInfoPopWindow.this.collectionList.remove(collection);
                        SpUtils.put(DetailLandInfoPopWindow.this.context, "collection", new Gson().toJson(DetailLandInfoPopWindow.this.collectionList));
                        EventBus.getDefault().post(new MessageEvent(Constant.MESSAGE_EVENT_UPDATA_COLLECTION_PROJECT));
                    }
                } else {
                    Glide.with(DetailLandInfoPopWindow.this.context).load(Integer.valueOf((int) R.mipmap.icon_collect)).into(DetailLandInfoPopWindow.this.ivCollection);
                    if (!DetailLandInfoPopWindow.this.collectionList.contains(collection)) {
                        DetailLandInfoPopWindow.this.collectionList.add(collection);
                        SpUtils.put(DetailLandInfoPopWindow.this.context, "collection", new Gson().toJson(DetailLandInfoPopWindow.this.collectionList));
                        EventBus.getDefault().post(new MessageEvent(Constant.MESSAGE_EVENT_UPDATA_COLLECTION_PROJECT));
                    }
                }
                DetailLandInfoPopWindow detailLandInfoPopWindow = DetailLandInfoPopWindow.this;
                detailLandInfoPopWindow.isCollection = !detailLandInfoPopWindow.isCollection;
            }
        });
    }

    public void upData(ArrayList<LandInfo> arrayList, String str, String str2, String str3, int i, Geometry geometry) {
        this.list.clear();
        this.list.addAll(arrayList);
        this.layerName = str;
        this.displayField = str2;
        this.dbName = str3;
        this.pkId = i;
        this.geometry = geometry;
        this.isCollection = false;
        this.adapter.notifyDataSetChanged();
        Glide.with(this.context).load(Integer.valueOf((int) R.mipmap.icon_uncollect)).into(this.ivCollection);
    }
}
